package me.winter.imgop;

import squint.SImage;

// Lossy Algorithm

// This class is a recursive version of wavelet. It will begin by applying the
// simple version of wavelet described above to an image. Then, if the original
// image is wider than two pixels, it should extract the left half of the result
// as a new image and recursively apply itself to the result. Finally, it should
// paste the result of this recursive call back into the left half of the image
// from which it extracted the left half.

public class RecursiveWaveletSimplifier extends ImageSimplifier {
    ImageSimplifier simplifier;
    ImageFilter halfer;
    ImageFilter paster;

    public RecursiveWaveletSimplifier() {
        simplifier = new WaveletSimplifier();
        halfer = new CopyLeftHalf();
    }

    @Override
	public SImage encode(SImage original) {
        if (original.getWidth() <= 2)
            return simplifier.encode( original );
        else {
            SImage encoded = encode( halfer.filter(simplifier.encode( original )) );
            return new Paster( encoded ).filter( simplifier.encode( original) );
        }
    }

    @Override
	public SImage decode(SImage original) {
        if (original.getWidth() <= 2)
            return simplifier.decode( original );
        else {
            SImage decoded = decode( halfer.filter( original ) );
            return simplifier.decode( new Paster( decoded ).filter( original ) );
        }
    }
}